require('./PageHome.styl');
const classNames = require("classnames")
const reactMixin = require('react-mixin');
const Actions = require('./actions');
const Store = require('./store');
import { Control } from 'react-keeper';
import { Boxs, NavBar } from 'saltui';
import ui from 'clientConfig/util/jsapi/ui';
const { HBox, Box, VBox } = Boxs;
const Rollup = require('components/rollup');
const WithRefresh = require('components/withrefresh');
const PendingList = require('components/pendinglist');
import { ready } from 'clientConfig/util/queryurlfield'
const ListWithSanitation = WithRefresh(
    PendingList,
    (pageNum, props, success, error) => {
        Actions.fetchSanitationList(pageNum, props, success, error)
    }
);
class Home extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            listdata: [],//班级列表
            classId: '',
            title:'',
            isMarker:false
        };
        this.handleOnLeftClick = this.handleOnLeftClick.bind(this)
        this.handleOnRightClick = this.handleOnRightClick.bind(this);
        this.refresh = this.refresh.bind(this);
    }
    handleOnLeftClick() {
        ui.close();
    }
    refresh(classId) {
        let t = this;
        for (let item of this.state.listdata) {
            if (item.classId == classId) {
                var title = item.title;
            }
        }
        this.setState({ classId,title }, () => {
            t.refs.ListWithSanitation.onRefresh()
        })
    }
    //右侧导航按钮
    handleOnRightClick() {
        Control.go('/home/addgrade/new');
    }
    share(){
        ready(() => { 
            dd.biz.util.share({
                type: 0,//分享类型，0:全部组件 默认； 1:只能分享到钉钉；2:不能分享，只有刷新按钮
                url: "https://www.baidu.com",
                title: "tring",
                content: "123",
                image: "",
                onSuccess : function() {
                    //onSuccess将在调起分享组件成功之后回调
                    /**/
                },
                onFail : function(err) {}
            })
         })
    }
    render() {
        let t = this;
        return (
            <div className="home">
                <NavBar
                    className={classNames({"ios-nav-bar":window.isIphone})}
                    isShow={false}
                    title='卫生管理'
                    onLeftClick={this.handleOnLeftClick.bind(this)}
                    onRightClick={this.handleOnRightClick.bind(this)}
                    rightText={this.state.isMarker=='yes'?'打分':''}
                />
                {this.state.classId &&
                    <Rollup
                        type="class"
                        title={this.state.title}
                        listdata={this.state.listdata}
                        refresh={this.refresh}
                    />}
                {this.state.classId &&
                    <ListWithSanitation
                        className="msg"
                        ref="ListWithSanitation"
                        leftSlip={false}
                        classId={this.state.classId}
                        type="sanitation"
                    />
                }
            </div>
        );
    }

    componentWillMount() {
    }

    componentDidMount() {
        Actions.getClassList();
        Actions.permissionJudgment();
    }

    componentWillReceiveProps(nextProps) {
    }

    shouldComponentUpdate(nextProps, nextState) {
        return true;
    }

    componentWillUpdate(nextProps, nextState) {
    }

    componentDidUpdate(prevProps, prevState) {
    }

    componentWillUnmount() {

    }
}
reactMixin.onClass(Home, Reflux.connect(Store));
module.exports = Home;
